Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use huge_tree=True in lxml parsing #2791

Merged

Conversation

yrrepy
Copy link
Contributor

@yrrepy yrrepy commented Nov 29, 2023

Description

Enabled lxml support for very deep trees and very long text content in the geometry Python class. (huge_tree=true)

For large lattices with many elements (>~500,000 elements) the Python Universe plotter would fail due to the "huge text node". With this change I can successfully universe.py plot my highly detailed voxel lattice.

The change implemented follows that counselled here:
https://stackoverflow.com/questions/11850345/using-python-lxml-etree-for-huge-xml-files

Fixes:
The error appearing during universe.py plotting was:

Traceback (most recent call last):
  File "/home/abc/Projects/UniversePlotter.py", line 116, in <module>
    my_geometry=openmc.Geometry.from_xml();
  File "/home/abc/.local/lib/python3.10/site-packages/openmc/geometry.py", line 296, in from_xml
    tree = ET.parse(path)
  File "src/lxml/etree.pyx", line 3541, in lxml.etree.parse
  File "src/lxml/parser.pxi", line 1879, in lxml.etree._parseDocument
  File "src/lxml/parser.pxi", line 1905, in lxml.etree._parseDocumentFromURL
  File "src/lxml/parser.pxi", line 1808, in lxml.etree._parseDocFromFile
  File "src/lxml/parser.pxi", line 1180, in lxml.etree._BaseParser._parseDocFromFile
  File "src/lxml/parser.pxi", line 618, in lxml.etree._ParserContext._handleParseResultDoc
  File "src/lxml/parser.pxi", line 728, in lxml.etree._handleParseResult
  File "src/lxml/parser.pxi", line 657, in lxml.etree._raiseParseError
  File "geometry.xml", line 435
lxml.etree.XMLSyntaxError: xmlSAX2Characters: huge text node, line 435, column 10000881

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
    - [ ] I have made corresponding changes to the documentation (if applicable)
    - [ ] I have added tests that prove my fix is effective or that my feature works (if applicable)

yrrepy and others added 2 commits November 28, 2023 14:44
Enabled larger tree nodes for large lattices with many elements. Needed for Python Universe plotter to plot large
Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @yrrepy! Sorry for the delay on this one.

@paulromano paulromano changed the title Geometry Python Class; lxml huge_tree=true Use huge_tree=True in lxml parsing Jan 17, 2024
@paulromano paulromano enabled auto-merge (squash) January 17, 2024 05:38
@paulromano paulromano merged commit 6391606 into openmc-dev:develop Jan 17, 2024
17 checks passed
@yrrepy yrrepy deleted the Universe-Plotter-lxml-huge_tree=True branch January 17, 2024 18:46
church89 pushed a commit to openmsr/openmc that referenced this pull request Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants